//获取下拉
var getallproj =  {
		getallproj_add : function() {
			
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=getallproj&address=http://103.37.166.4:7777/StateGrid/proj.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
					param = JSON.parse(param).data;
//					getclassrooms.createTable(param);
//					 alert(param);
					var str = '';
					  for(var i in param) {
					str += '<option value="'+param[i].projectId+'" id="xuanzhong">'+param[i].projectName+'</option>';
					/*alert(param[i].projectId)
					alert(param[i].projectName)*/
					}
					  $(str).appendTo("#yanlian_project")
				},
				error: function(){
				}
			});
		},
	}

//新增
var  createcr =  {
		createcr_add : function() {
			var  suid = sessionStorage.getItem("suid_name");
			var sel=document.getElementById("yanlian_project");
			prid = sel.options[sel.selectedIndex].value;
			var yanlian_name = $("#yanlian_name").val();
			var yanlian_desc = $("#yanlian_desc").val();
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=createcr,suid=" + suid +",prid=" + prid +",name="+ yanlian_name +",desc="+ yanlian_desc +"&address=http://103.37.166.4:7777/StateGrid/proj.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
//					alert(param);
					$(".addPop").hide(500);
					$(this).removeClass("overHiden");
					location.reload();
				},
				error: function(){
				}
			});
		},
	}

//删除
var  del =  {
		delete_yl : function() {
			var crid = sessionStorage.getItem("crid");	
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=delcr,del=1,crid=" + crid +"&address=http://103.37.166.4:7777/StateGrid/cra.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
					param = JSON.parse(param).data;
//					alert(param.isDel);
							$(".delPop").hide(500);
							$(this).removeClass("overHiden");
							location.reload();
				},
				error: function(){
				}
			});
		},
	}

//获取文档
var getMater = {
		getMater_list : function(){
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=getmater,type=refdoc,suid=editor1&address=http://103.37.166.4:7777/StateGrid/mat.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
//					alert(param);
					param = JSON.parse(param).data;
					getMater.getMater_xs(param)
				},
				error: function(){
				}
			});
		},
		getMater_xs : function(param){
			$("#wenDang").html("");
			var str = ""
			var j = 0;
//				str += '<tr><th><input type="checkbox"></th><th>素材编号</th><th>素材名称</th><th>操作</th></tr>';
				str += '<tr><td><input type="checkbox" name="" id="" value="" /></td><td>素材编号</td><td>素材名称 </td><td>是否被引用</td><td>被引用对象</td></tr>';
			for(var i in param){
				j++;
				str += '<tr><td><input name="cb" onclick="sigleChecked(this)"   value="'+param[i].materInfoId+'" type="checkbox"/></td><td>'+j+'</td><td>'+param[i].materName+'</td><td>是</td><td>'+param[i].materFileName+'</td></tr>';
			}
			$(str).appendTo("#wenDang");
			
		} 
}
//$('input[name="cb"]:checked').each(function(){    
//	   chk_value.push($(this).val());    
//	  });    
function sigleChecked(u){
   if ($(u).prop('checked')) {
	   $(':checkbox[name=cb]').removeAttr('checked');
	   $(u).prop('checked',true);
   }
}
//function a(){
//	var a = $('input[name="cb"]:checked').val();
//	console.info(a);
//}
//新增文档
var addgetMater = {
		addgetMater_list : function(){
			var materid = $('input[name="cb"]:checked').val();
//			console.info(materid);//控制台打印
			var crid = sessionStorage.getItem("crid");
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=addmc,crid="+ crid +",materid="+ materid +",desc=4test&address=http://103.37.166.4:7777/StateGrid/mat.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
//					alert(param);
					param = JSON.parse(param)
					
					addgetMater.addgetMater_xs(param)
					$(".adddocPop2").hide(500);
					$(this).removeClass("overHiden")
				},
				error: function(){
				}
			});
		},
		addgetMater_xs : function(param){
			var a = param.materInfo.materName
			$("#addWenDang").html("");
			var str = "";
			var j=0 ;
				j++;
				str +='<tr id="'+param.crjmId+'"><td><input type="checkbox" name="" id="" value="" /></td><td>'+j+'</td><td>'+param.materInfo.materName+'</td><td><a onclick="addgetMater.deleteWd(\''+param.crjmId+'\')" >删除</a></td></tr>';
			$("#addwenDang").append(str);
		},
		deleteWd :function(crjmid){
//			alert(crjmid);
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=delmc,crjmid="+ crjmid +"&address=http://103.37.166.4:7777/StateGrid/mat.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
//					alert(param);
					$("#"+crjmi).empty();
					param = JSON.parse(param)
				},
				error: function(){
				}
			});
		}
}

/*//绑定事件
var binding = {
		binding_select : function(){
			$.ajax({
				type : "GET",
				url : "http://127.0.0.1:8080/yl-websocket/transmit?param='m=delcr,del=1,crid=" + crid +"&address=http://103.37.166.4:7777/StateGrid/cra.do",
				scriptCharset: 'utf-8', 
				success : function(param) {
					param = JSON.parse(param).data;
					alert(param.isDel);
							
						alert(param);
						$(".delPop").hide(500);
						$(this).removeClass("overHiden");
						location.reload();
				},
				error: function(){
				}
			});
			
		}
}
*/







$(function() {
	//新增
	$("#addP").click(function() {
		$("#yanlian_name").html("");
		$("#yanlian_desc").html("");
		$(".addPop").show(500);
		$(this).addClass("overHiden");
		getallproj.getallproj_add();
	});
	
	/*新增----添加文档*/
	$("#addDoc2").click(function() {
		//alert("ok")
		$(".adddocPop2").show(500);
		$(this).addClass("overHiden");
		getMater.getMater_list();
		
	});
	
	//保存文档
	$("#bcWendang").click(function(){
		addgetMater.addgetMater_list();
	})
	
	
	//删除
	$("#delete_yl").click(function(){
		del.delete_yl();
	})
	//创建
	$("#getallproj").click(function(){
		createcr.createcr_add();
	})
	
});
